package com.xhh.nphm.web.controller.system;

import com.xhh.nphm.common.core.controller.BaseController;
import com.xhh.nphm.common.core.domain.AjaxResult;
import com.xhh.nphm.common.core.domain.entity.SysRole;
import com.xhh.nphm.common.core.domain.entity.SysUser;
import com.xhh.nphm.common.core.page.PageDomain;
import com.xhh.nphm.common.core.page.TableDataInfo;

import com.xhh.nphm.common.core.text.Convert;
import com.xhh.nphm.system.domain.TtelBlackEty;
import com.xhh.nphm.system.domain.TtelGetDealEty;
import com.xhh.nphm.system.domain.TtelRedEty;
import com.xhh.nphm.system.service.ITelNameListService;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/system/telNameList")
public class TelNameListController extends BaseController {
    private String prefix = "system/telNameList";
    @Autowired
    private ITelNameListService telNameListService;

    /**
     * 获取所有黑名单号码
     * @param ttelBlackEty
     * @return
     */
    @RequestMapping("listBlack")
    public TableDataInfo listBlack(TtelBlackEty ttelBlackEty) {
        startPage();
        List<TtelBlackEty> list = telNameListService.listBlack(ttelBlackEty);
        return getDataTable(list);
    }
    /**
     * 获取所有红名单号码
     * @param ttelRedEty
     * @return
     */
    @RequestMapping("listRed")
    public TableDataInfo listRed(TtelRedEty ttelRedEty) {
        startPage();
        List<TtelRedEty> list = telNameListService.listRed(ttelRedEty);
        return getDataTable(list);
    }


    /**
     * 跳转黑名单页面
     * @return
     */
    @RequiresPermissions("telNameList:telBlack:view")
    @GetMapping("/telBlack")
    public ModelAndView telBlack() {
        return new ModelAndView(prefix + "/telBlack");
    }

    /**
     * 跳转红名单页面
     * @return
     */
    @RequiresPermissions("telNameList:telRed:view")
    @GetMapping("/telRed")
    public ModelAndView telRed() {
        return new ModelAndView(prefix + "/telRed");
    }

    /**
     * 跳转新增黑名单页面
     * @return
     */
    @RequiresPermissions("telNameList:addBlack:view")
    @GetMapping("/addBlack")
    public ModelAndView addBlack() {
        return new ModelAndView(prefix + "/addBlack");
    }


    /**
     * 新增黑名单号码
     * @param ttelBlackEty
     * @return
     */
    @RequestMapping("addBlack")
    public AjaxResult addBlack(TtelBlackEty ttelBlackEty) {
        return toAjax(telNameListService.saveBlack(ttelBlackEty));
    }

    /**
     * 跳转红名单页面
     * @return
     */
    @RequiresPermissions("telNameList:addRed:view")
    @GetMapping("/addRed")
    public ModelAndView addRed() {
        return new ModelAndView(prefix + "/addRed");
    }


    /**
     * 新增红名单号码
     * @param ttelRedEty
     * @return
     */
    @RequestMapping("addRed")
    public AjaxResult addRed(TtelRedEty ttelRedEty) {
        return toAjax(telNameListService.saveRed(ttelRedEty));
    }

    /**
     * 删除黑名单号码
     * @param ids
     * @return
     */
    @RequiresPermissions("telNameList:removeBlack:view")
    @PostMapping("/removeBlack")
    @ResponseBody
    public AjaxResult removeBlack(Integer... ids) {
        return toAjax(telNameListService.deleteBlack(ids));
    }

    /**
     * 删除红名单号码
     * @param ids
     * @return
     */
    @RequiresPermissions("telNameList:removeRed:view")
    @PostMapping("/removeRed")
    @ResponseBody
    public AjaxResult removeRed(Integer...  ids) {
        return toAjax(telNameListService.deleteRed(ids));
    }

    /**
     * 编辑黑名单号码
     */
    @RequiresPermissions("telNameList:editBlack:view")
    @GetMapping("/editBlack/{id}")
    public ModelAndView editBlack(@PathVariable("id") Integer id, ModelMap mmap) {
        mmap.put("blacks", telNameListService.selectBlack(id));
        return new ModelAndView(prefix + "/editBlack");
    }

    /**
     * 编辑红名单号码
     */
    @RequiresPermissions("telNameList:editRed:view")
    @GetMapping("/editRed/{id}")
    public ModelAndView editRed(@PathVariable("id") Integer id, ModelMap mmap) {
        mmap.put("reds", telNameListService.selectRed(id));
        return new ModelAndView(prefix + "/editRed");
    }


    /**
     * 编辑保存黑名单号码
     * @param ttelBlackEty
     * @return
     */
    @PostMapping("/editBlack")
    @ResponseBody
    public AjaxResult editBlack( TtelBlackEty ttelBlackEty) {
        return toAjax(telNameListService.editBlack(ttelBlackEty));
    }

    /**
     * 编辑保存黑名单号码
     * @param ttelRedEty
     * @return
     */
    @PostMapping("/editRed")
    @ResponseBody
    public AjaxResult editRed( TtelRedEty ttelRedEty) {
        return toAjax(telNameListService.editRed(ttelRedEty));
    }
}
